home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
RTF
/
elements.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
117 lines
/* $Header: /usr/people/pcd/Src/RTF/RCS/elements.C,v 1.1 92/11/23 12:58:54 pcd Exp Locker: pcd $
*/
#include "elements.h"
#include "rtftoken.h"
#include "view.h"
#include "debug.h"
Inches ParagraphFormat::default_tab_width_;
int debug_tabs = 0;
Qty
NewLineFlow::character_shape(TextPosition, Qty q,
Extent avail, Extent& used, int) const
{
Coord h = font_ascent() + space_after();
REQUIRE(h <= avail.bottom() - avail.top()
&& avail.right() > avail.current_x(), return 0);
used.ascent(font_ascent());
used.descent(space_after());
/* x2 is space left to justify... */
used.x2 = used.x0 = avail.right() - avail.current_x();
return q;
}
ParagraphFormat::ParagraphFormat()
{
normal();
}
void
ParagraphFlow::line_shape(TextPosition where, Extent& margins) const
{
/* find first renderable TextPosition */
LRBox a(0), b(0);
Extent avail(0,0,1,0,0); // minimal
Extent used;
TextPosition aa = a.format(this, 0, bytes(), avail, used);
TextPosition bb = b.format(this, where, bytes(), avail, used);
margins.x1 = view().hinches(fmt_.left_indent);
margins.y0 = 0;
if(aa == bb){
margins.x1 += view().hinches(fmt_.first_indent);
margins.y0 = view().vinches(fmt_.space_before);
}
switch(fmt_.justification){
case ParagraphFormat::quad_center:
margins.x0 = 2;
break;
case ParagraphFormat::quad_right:
margins.x0 = 1;
break;
default:
margins.x0 = 0;
break;
}
margins.x2 = view().hinches(fmt_.right_indent);
margins.y1 = view().vinches(fmt_.space_between);
}
Coord
TabFlow::next_tab_stop(Coord here) const
{
int i;
Coord x;
for(i=0; here > (x = view().hinches(fmt_.tab(i))); i++);
return x;
}
Qty
TabFlow::character_shape(TextPosition, Qty q,
Extent avail, Extent& used, int w) const
{
Coord x = avail.x0 + next_tab_stop(avail.current_x() - avail.x0);
used.y0 = 1;
used.y1 = 0;
used.x2 = 0;
Debug(tabs, ("tab? left:%d tab: %d(%g) right: %d\n",
avail.x0, x, tx_, avail.x2));
if(x > avail.right() || avail.current_x() >= avail.right()){
if(w == 0){ // don't need to fit whole tab.
used.x0 = avail.right() - avail.current_x();
return q;
}else
return 0;
}
used.x0 = x - avail.current_x();
if(used.x0 < 0) used.x0 = 0;
return q;
}